package com.tedu.pj.common.aspect;

import com.tedu.pj.common.anntation.RequireCache;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/10/22
 */
@Component
public class CacheAdvisor extends StaticMethodMatcherPointcutAdvisor {

    public CacheAdvisor(){
        setAdvice(new CacheAdvice());
    }
    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        try {
            Method declaredMethod = targetClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
            RequireCache annotation = declaredMethod.getAnnotation(RequireCache.class);
            if (annotation!=null){
                return true;
            }
        }catch (Exception e){

        }
        return false;
    }
}
